package io;

import java.io.*;

/**
 * @author IT枫斗者
 * @ClassName ObjectOutputStreamDemo.java
 * @From www.javatiaozao.com
 * @Description TODO
 */
public class ObjectOutputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
       //ObjectOutputStream(OutputStreamout)
        //创建一个写入指定的OutputStream的ObjectOutputStream
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("myStream/osw.txt"));
//        //创建对象
//        Student s = new Student("刘亦菲", 20);
//        oos.writeObject(s);
//        oos.flush();
//        oos.close();

        //ObjectInputStream(InputStream
        //in)创建从指定的InputStream读取的ObjectInputStream
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("myStream/osw.txt"));
        //读取对象
        Object obj = ois.readObject();

        Student s1 = (Student)obj;
        System.out.println(s1.getName() + "==" + s1.getAge());

        ois.close();
    }
}
